package com.raccoonagents.tools.cascet2d.model;
/**
 * 
 * @author Kari Kuvaja
 * Vector class to be used in calculations.
 */

public class Vector2f {

	public Vector2f(final float x, final float  y){
		this.x = x;
		this.y = y;
	}
	
	private float length;
	
	@Override
	public String toString() {
		return this.getClass().getName() + " X : " + x + " Y : " + y;
	}
	public float x;
	public float y;
	public float getY() {
		return y;
	}
	public void setY(final float y) {
		this.y = y;
	}
	
	private void calcLength(){
		length = (float) Math.sqrt(x*x + y*y);
	}
	
	public float getX() {
		return x;
	}
	public void setX(final float x) {
		this.x = x;
	}
	
	public float getLength(){
		calcLength();
		return length;
	}
	
	public Vector2f add(final Vector2f v2){
		return new Vector2f(this.x + v2.x, this.y + v2.y);
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Float.floatToIntBits(x);
		result = prime * result + Float.floatToIntBits(y);
		return result;
	}
	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final Vector2f other = (Vector2f) obj;
		if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x)) {
			return false;
		}
		if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y)) {
			return false;
		}
		return true;
	}
	
	
}
